﻿#pragma once

#include <string>
#include <sstream>
#include <winrt/base.h>

namespace Logging
{
    enum class Level : uint8_t
    {
        Debug = 0,
        Info,
        Warn,
        Error,
        None
    };

    // 配置
    void SetMinLevel(Level level) noexcept;
    void EnableConsole(bool enabled) noexcept;
    void EnableFile(bool enabled) noexcept;
    void SetFilePath(const std::string& path) noexcept;
    Level GetMinLevel() noexcept;
    bool IsConsoleEnabled() noexcept;
    bool IsFileEnabled() noexcept;
    std::string GetFilePath() noexcept;

    // 统一日志入口（推荐）
    void Log(Level level, const std::string& message) noexcept;

    // 兼容/便捷重载（将按 Info 级别写入）
    void Log(const char* message) noexcept;
    void Log(const std::string& message) noexcept;
    void Log(const winrt::hstring& message) noexcept;
    void Log(const std::ostringstream& message) noexcept;
    void Log(int message) noexcept;

    // 文件直写（无级别，追加）
    void LogToFile(const std::string& message) noexcept;

    // ToString 工具，便于宏内转换
    inline std::string ToString(const char* s) { return s ? std::string{s} : std::string{}; }
    inline std::string ToString(const std::string& s) { return s; }
    inline std::string ToString(const winrt::hstring& s) { return winrt::to_string(s); }
    inline std::string ToString(const std::ostringstream& s) { return s.str(); }
    inline std::string ToString(int v) { return std::to_string(v); }
}

// 宏：始终编译进来，由运行时开关控制是否输出
#define LOG_DEBUG(msg) ::Logging::Log(::Logging::Level::Debug, ::Logging::ToString(msg))
#define LOG_INFO(msg)  ::Logging::Log(::Logging::Level::Info,  ::Logging::ToString(msg))
#define LOG_WARN(msg)  ::Logging::Log(::Logging::Level::Warn,  ::Logging::ToString(msg))
#define LOG_ERROR(msg) ::Logging::Log(::Logging::Level::Error, ::Logging::ToString(msg))

